package com.irdstudio.efp.nls.service.impl.ms;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.nls.service.dao.MsZxInfoDao;
import com.irdstudio.efp.nls.service.domain.MsZxInfo;
import com.irdstudio.efp.nls.service.facade.ms.MsZxInfoService;
import com.irdstudio.efp.nls.service.vo.MsZxInfoVO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 需求编号：xxxxxx<br/>
 * 问题编号：<br/>
 * 功能描述：马上征信信息处理实现类<br/>
 * 创建时间：2020/4/29 19:28
 * @Author tiankg
 * @Version 1.0
 * @Since 1.0
 */
@Service("msZxService")
public class MsZxInfoServiceImpl implements MsZxInfoService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(MsZxInfoServiceImpl.class);

    @Autowired
    private MsZxInfoDao msZxInfoDao;

    /**
     * 功能描述：新增征信信息<br/>
     * 开发人员：tiankg<br/>
     * @Version 1.0
     * @Since   1.0
     * @Param  [insertMsZxInfo]
     * @Return int
     */
    @Override
    public int insertMsZxInfo(MsZxInfoVO insertMsZxInfo) throws Exception {
        logger.debug("当前新增数据为:" + insertMsZxInfo.toString());
        int num = 0;
        try {
            MsZxInfo msZxInfo = new MsZxInfo();
            beanCopy(insertMsZxInfo, msZxInfo);
            num = msZxInfoDao.insertMsZxInfo(msZxInfo);
        } catch (DuplicateKeyException dke) {
            throw new Exception("新增数据发生异常，主键冲突!");
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
            throw e;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键查询马上征信信息
     */
    @Override
    public MsZxInfoVO queryByPk(MsZxInfoVO inMsZxInfoVo) {

            logger.debug("当前查询参数信息为:" + inMsZxInfoVo);
            try {
                MsZxInfo queryMsZxInfo = new MsZxInfo();
                beanCopy(inMsZxInfoVo, queryMsZxInfo);
                MsZxInfo queryRslMsZxInfo = msZxInfoDao.queryByPk(queryMsZxInfo);
                if (Objects.nonNull(queryRslMsZxInfo)) {
                    MsZxInfoVO outMsZxInfoVo = new MsZxInfoVO();
                    beanCopy(queryRslMsZxInfo, outMsZxInfoVo);
                    logger.debug("当前查询结果为:" + outMsZxInfoVo.toString());
                    return outMsZxInfoVo;
                } else {
                    logger.debug("当前查询结果为空!");
                }
            } catch (Exception e) {
                logger.error("查询数据发生异常!", e);
            }
            return null;
    }
}
